﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace RoadTeam.FineFile.Code
{
   public class ReFileOpera
    {
        public String SourceDir { get; set; }
        public String OutDir { get; set; }
        public String FileDirAndName { get; set; }

        public void CopyFile(string SourceDir, string OutDir, string FileDirAndName)
        {
            //把路径标准化,把/替换为\
            FileDirAndName = FileDirAndName.Replace("/", "\\");

            String Temp = SourceDir + "\\" + FileDirAndName;
            //如果指定的文件不存在,则不创建该目录
            if (!File.Exists(Temp)) return;

            String OutDirPath = OutDir + "\\" + FileDirAndName;

            OutDirPath = OutDirPath.Substring(0, OutDirPath.LastIndexOf("\\"));
           // String SourcePath = Temp.Substring(0, Temp.LastIndexOf("\\"));

            //如果输出路径不存在,则创建
            if (!Directory.Exists(OutDirPath))
                Directory.CreateDirectory(OutDirPath);

           // FileInfo fileinfo = new FileInfo(Temp);
            File.Copy(Temp, OutDir + "\\" + FileDirAndName, true);
        }
    }
}
